//
//  RainView.m
//  UI05_作业
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#import "RainView.h"

@implementation RainView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}
- (void)createSubView{
    for (NSInteger i = 0; i <= 8; i++) {
        UIView *view = [[UIView alloc] init];
        view.frame = CGRectMake(20 * i  , 20 * i, ScreenWidth - 40 * i , ScreenHeight - 40 * i);
        view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255) / 255.0 green:arc4random_uniform(255) / 255.0 blue:arc4random_uniform(255) / 255.0 alpha:1];
        view.tag = 1000 + i;
        [self addSubview:view];
    }
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(AddTimer) userInfo:nil repeats:YES];

}
- (void)AddTimer{
    UIView *view1 = [[UIView alloc] init];
    view1.backgroundColor = [self viewWithTag:1000].backgroundColor;
    [self viewWithTag:1000].backgroundColor = [self viewWithTag:1001].backgroundColor;
    [self viewWithTag:1001].backgroundColor = [self viewWithTag:1002].backgroundColor;
    [self viewWithTag:1002].backgroundColor = [self viewWithTag:1003].backgroundColor;
    [self viewWithTag:1003].backgroundColor = [self viewWithTag:1004].backgroundColor;
    [self viewWithTag:1004].backgroundColor = [self viewWithTag:1005].backgroundColor;
    [self viewWithTag:1005].backgroundColor = [self viewWithTag:1006].backgroundColor;
    [self viewWithTag:1006].backgroundColor = [self viewWithTag:1007].backgroundColor;
    [self viewWithTag:1007].backgroundColor = [self viewWithTag:1008].backgroundColor;
    [self viewWithTag:1008].backgroundColor = view1.backgroundColor;
    [self addSubview:view1];
    
}
@end
